﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Xiaozilang_Ordering_System
{
    public partial class losepwd2 : Form
    {
        public static int Judge = 0;
        public losepwd2()
        {
            InitializeComponent();
            textBox1.Enter += new EventHandler(textBox1_Enter);
            textBox1.Leave += new EventHandler(textBox1_Leave);
            textBox2.Enter += new EventHandler(textBox2_Enter);
            textBox2.Leave += new EventHandler(textBox2_Leave);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "新密码" && textBox2.Text != "确认新密码")
            {
                bool reader;
                bool reader2;
                string sql = null;

                try
                {

                    //商家更改密码

                    sql = "update Business set BSpwd='" + textBox1.Text + "' where BStel='" + losepwd.Number1 + "'";
                    reader2 = DBHelper.GetNonQuery(sql);
                    //用户更改密码

                    sql = "update User1 set USpwd='" + textBox1.Text + "' where UStel='" + losepwd.Number1 + "'";
                    reader = DBHelper.GetNonQuery(sql);
                    if (reader == true||reader2==true)
                    {
                        MessageBox.Show("修改成功");
                        this.Close();


                    }

                }
                catch (Exception ex)
                {
                    MessageBox.Show("系统错误，原因：" + ex.Message);
                }
            }
            else
            {
                MessageBox.Show("请输入相关信息");
            }
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            if (textBox1.Text == "新密码")
            {
                textBox1.Text = "";
            }
        }
        private void textBox1_Leave(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox1.Text = "新密码";
            }
        }
        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "确认新密码")
            {
                textBox2.Text = "";
            }
        }
        private void textBox2_Leave(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                textBox2.Text = "确认新密码";
            }
            if (textBox2.Text != textBox1.Text)
            {
                MessageBox.Show("与第一次密码不一致，请重新输入");
                textBox2.Text = "确认新密码";
            }
        }

        private void losepwd2_Load(object sender, EventArgs e)
        {
            label1.Text = "新密码";
            label2.Text = "确认新密码";
            label1.BackColor = Color.Transparent;
            label2.BackColor = Color.Transparent;
        }
    }
}